/*
 * 人人信用管理有限公司版权所有.
 * 
 * @Description:
 * 
 * @author: liyuliang
 * 
 * @date: 20 Apr 2017 10:44:16 am
 * 
 * 注意：本内容仅限于人人信用管理有限公司内部传阅，禁止外泄以及用于其他的商业目的.
 */

package com.rrx360.common.web.sitemesh;

import javax.servlet.jsp.JspException;

import com.rrx360.common.web.tag.ref.BaseTag;

public class TemplateTag extends BaseTag {

  private static final long serialVersionUID = 8675616981606545498L;

  public int doStartTag() throws JspException {
    String templatePath = getAttribute("path");
    String templateName = getAttribute("name");
    if (templatePath == null && templateName == null) {
      return SKIP_BODY;
    }
    if ((templatePath != null && templatePath.length() == 0)
        || templateName != null && templateName.length() == 0) {
      this.pageContext.getRequest().setAttribute("templates", new String[] {});
      return SKIP_BODY;
    }

    String[] templates = null;
    if (templatePath != null) {
      templates = templatePath.split(",");
    } else {
      templates = templateName.split(",");
      String[] templatesPath = new String[templates.length];
      for (int i = 0; i < templates.length; i++) {
        templatesPath[i] = "/WEB-INF/common/decorators/" + templates[i] + ".jsp";
      }
      templates = templatesPath;
    }
    this.pageContext.getRequest().setAttribute("templates", templates);
    return SKIP_BODY;
  }
}
